/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package montecarloMulti;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

import montecarlo.GUI.MCGUI;
import montecarloSimple.ModelSimple;
/**
 *
 * @author Antoine
 */
public class ControllerMulti {
    
	protected ModelSimple model;
    protected MCGUI view;
    protected ModelMultiThreads model2;
    
    public ControllerMulti(ModelSimple model, MCGUI view) throws FileNotFoundException, IOException{
        this.model=model;
        this.view=view;
        this.view.launch(new Launch());
        view.setComboBoxes(ModelSimple.readFile());
    }

    public ControllerMulti(ModelMultiThreads model, MCGUI view) throws FileNotFoundException, IOException{
        this.model2=model;
        this.view=view;
        this.view.launch(new Launch());
        view.setComboBoxes(ModelMultiThreads.readFile());
    }
    
public class Launch implements ActionListener{
    
	public void actionPerformed(ActionEvent e){
        String flag;
        Double S,X,T,r,b,v,lblResult = null;
        Integer nSteps,nSimulation;
        Double tempsCalcul = null;
       
        //recupere donn�es
        
        flag=view.flag.getSelectedItem().toString();
        S=Double.parseDouble(view.S.getSelectedItem().toString());
        X=Double.parseDouble(view.X.getSelectedItem().toString());
        T=Double.parseDouble(view.T.getSelectedItem().toString());
        r=Double.parseDouble(view.r.getSelectedItem().toString());
        b=Double.parseDouble(view.b.getSelectedItem().toString());
        v=Double.parseDouble(view.v.getSelectedItem().toString());
        nSteps=Integer.parseInt(view.nSteps.getSelectedItem().toString());
        nSimulation=Integer.parseInt(view.nSimulation.getSelectedItem().toString());
        
        //lance le calcul
        
        try {
			
        	final long start = System.nanoTime();
        	     	
          	lblResult=model2.monteCarloStandardOption(flag, S, X, T, r, b, v, nSteps, nSimulation);
          	
          	final long end = System.nanoTime();
          	
          	tempsCalcul=(end-start)/1.0e9;
          	
          	System.out.println(tempsCalcul);
        	
        	
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ExecutionException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
        
        //affiche reultat
        
        view.setLblResult(lblResult);
        view.setTempsCalcul(tempsCalcul);
        view.setVisible(true);
    }
}
}
